﻿// JScript 文件
document.oncontextmenu=function(e){return false;} 
var mEntBh = ""
var strsql = null;
var major = 0;
var minor = 0;
var EntMajor = 0;
var EntMinor = 0;
var id0 = null;

var vList = new CtnListCtrl("vList");
vList.create("result");
vList.bfill = 1;
vList.pagesize = 10;
vList.onGoPage = gotoPage;
vList.onRowClick  = onRowClick;
vList.onRowRClick  = onRowClick;


var Menu = new CtnMenuCtrl("Menu");


function initEntInfo()
{
    if($V("EntInfo") != "")
    {
        var vData = $V("EntInfo")
        var vXmlDoc = CtnXML.getXmlDoc()
        vXmlDoc.loadXML(vData)
        var n = 0 
        var vNode = vXmlDoc.selectNodes("GdzcLst/Item")
        for(var i=0; i< vNode.length; i++)
        {
            var maj = vNode[i].attributes[0].nodeValue
            var min = vNode[i].attributes[1].nodeValue
            var Ent = vNode[i].attributes[2].nodeValue        
            $("Select_Ent").options[n++] = new Option(Ent, [maj, min]);
        }
        EntMajor = vNode[0].attributes[0].nodeValue
        EntMinor = vNode[0].attributes[1].nodeValue
    }
    
    $("result").oncontextmenu  = function (evt)
    
    { 
        Menu.clear();
        with(Menu)
            {            
                addEvent("查看","View()");
                addEvent("编辑", "Edit()"); 
                addEvent("添加","Add()");      
            } 
        Menu.show(evt);
        return false;
    }
}

function View()
{
    if(id0 == null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
    top.ExecuteATool(top.m_vt.FUN_ATT, [major, minor, id0.text, 'view', null])
}

function Edit()
{
    if(id0 == null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
    top.ExecuteATool(top.m_vt.FUN_ATT, [major, minor, id0.text, 'edit', AttEdit])
}

function Add()
{
    if(id0 == null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
    top.ExecuteATool(top.m_vt.FUN_ATT, [major, minor, id0.text, 'add', AttAdd])
}

function AttEdit(dlg)
{
    var vGrid = dlg.wnd.getXml()
    var xmlDoc = CtnTrans.getText("/main.ashx?_method=EditGdzc", "post", escape(vGrid))
    if (!CtnError.validate(xmlDoc))
    {
        CtnError.show();
    }
    dlg.close()
    vList.goPage(vList.curpage);
}

function AttAdd(dlg)
{
    var vGrid = dlg.wnd.getXml()
    var xmlDoc = CtnTrans.getText("/main.ashx?_method=AddGdzcInfo", "post", escape(vGrid))
    if (!CtnError.validate(xmlDoc))
    {
        CtnError.show();
    }
    dlg.close()
    vList.goPage(1);
}

function EntChange()
{
    var EntInfo = $V("Select_Ent").split(',')
    if($V("EntInfo") != "")
    {
        var vData = $V("EntInfo")
        var vXmlDoc = CtnXML.getXmlDoc()
        vXmlDoc.loadXML(vData)
        var n = 0 
        var vNode = vXmlDoc.selectNodes("GdzcLst/Item")
        for(var i=0; i< vNode.length; i++)
        {
            var maj = vNode[i].attributes[0].nodeValue
            var min = vNode[i].attributes[1].nodeValue       
            if (EntInfo[0] == maj && EntInfo[1] == min)
            {
                $("Select_Type").innerHTML = ""         
                if(vNode[i].childNodes.length > 1)
                {
                    for(var j=0; j< vNode[i].childNodes.length; j++)
                    {
                        var typeval = vNode[i].childNodes[j].attributes[0].nodeValue
                        var bh      = vNode[i].childNodes[j].attributes[1].nodeValue
                        $("Select_Type").options[n++] = new Option(typeval, bh);
                    }
                }
                mEntBh = vNode[i].childNodes[0].attributes[1].nodeValue
                break;
            }
            EntMajor  = EntInfo[0]
            EntMinor  = EntInfo[1]
        }
        
    } 
}

function EntTypeChange()
{
    mEntBh = $V("Select_Type")
}

function Query_onclick()
{
    major = 95
    minor = 815
    strsql = "GDZCBH = '"+mEntBh+"'";
    //Sql为空
    if(strsql == "" || strsql == null)
    {
        top.CtnDlg.error("查询条件为空");
        return ;
    }
    vList.onGoPage(1);
}

function AddEnt_onclick()
{
    top.ExecuteATool(top.m_vt.FUN_ATT, [EntMajor, EntMinor, '', 'add', AddEnt])
}

function AddEnt()
{
 
}

function onRowClick(evt, rowno)
{
    var rowobj = vList.getRow(rowno);
    id0 = rowobj.getCell("id0");
}


function gotoPage(page)
{
    var vUrl = "_method=getGdzcInfo&major="+escape(major)+"&minor="+escape(minor)+"&strsql="+escape(strsql)+"&pageno="+page+"&size="+vList.pagesize
    var vData = CtnTrans.getText("/main.ashx", "post", vUrl);
    if (!CtnError.validate(vData))
    {
        CtnError.show();
        return;
    }
    else if(vData == "false")
    {
        CtnDlg.msg("没有符合条件的记录!") 
    }
    else
    {
        vList.reset();
        vList.insertXml(vData, 1);
        vList.show();
    }
}